/*
 * @lc app=leetcode.cn id=1281 lang=typescript
 *
 * [1281] 整数的各位积和之差
 */

// @lc code=start
function subtractProductAndSum(n: number): number {
    let cache = [];
    while (n) {
        cache.push(n % 10);
        n = Math.floor(n / 10);
    }
    return cache.reduce((a, b) => a * b, 1) - cache.reduce((a, b) => a + b, 0);
}
// @lc code=end
